package com.laxcen.pluginlib;

import android.app.Application;

import com.laxcen.pluginlib.app.AndroidApiHook;
import com.laxcen.pluginlib.msg.PluginInitializer;
import com.laxcen.pluginlib.util.LogUtil;

public final class PluginManager {

    private static PluginLoadListener runtimeListener;

    public static Application application;
    private PluginManager() {
    }

    public static void init(Application app, PluginLoadListener listener) {
        runtimeListener = listener;
        boolean isDebug = listener.isDebug();
        application = app;
        Const.IS_DEBUG = isDebug;
        PluginInitializer.init();
        try {
            AndroidApiHook.hookInstrumentation();
        } catch (Throwable ex) {
            LogUtil.e(ex.getMessage(), ex);
        }

        try {
            AndroidApiHook.hookActivityManager();
        } catch (Throwable ex) {
            LogUtil.d(ex.getMessage(), ex);
        }

        try {
            AndroidApiHook.hookPackageManager();
        } catch (Throwable ex) {
            LogUtil.d(ex.getMessage(), ex);
        }
    }


    public static PluginLoadListener getRuntimeListener() {
        return runtimeListener;
    }
}
